<?php
/**
 * News model, using for getting news from MovableType ws
 */
class News extends AppModel{
	var $name = 'News';
	var $useTable = false;
	public function getNews($limit = 5){
		Configure::load('news');
		$url = Configure::read('url') ;
		$request = array(
			'auth' => array(
				'method' => 'Basic',
				'user' => Configure::read('BasicAuth.user'),
				'pass' => Configure::read('BasicAuth.pass')
			)
		);
		App::import('Core', 'HttpSocket');
		$httpSocket = new HttpSocket();
		$results = $httpSocket->get($url, array('limit' => $limit), $request);
		try{
			$object = json_decode($results);
			if(is_object($object)){
				if($object->status == 'yes'){
					return $object->data;
				}
			}else{
				return array();
			}
		}  catch (Exception $ex){
			return array();
		}
	}
}
?>
